package com.googeioextended.youtubebetter;

import java.io.IOException;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore.Video;
import android.util.Log;
//
//import com.google.api.client.googleapis.GoogleHeaders;
//import com.google.api.client.googleapis.json.JsonCParser;
//import com.google.api.client.http.HttpRequest;
//import com.google.api.client.http.HttpTransport;
//import com.google.api.client.http.javanet.NetHttpTransport;
//import com.google.api.client.json.jackson.JacksonFactory;
//import com.google.gdata.data.youtube.VideoFeed;

public class BrowseVideos extends Activity {
	public String TAG = "BrowseVideos";

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// startVideo("ygl7JINvawY");
		setContentView(R.layout.main);
		Test();
	}

	public void Test() {
//		JsonCParser parser = new JsonCParser();
//		parser.jsonFactory = new JacksonFactory();
//		// set up the Google headers
//		GoogleHeaders headers = new GoogleHeaders();
//		headers.setApplicationName("Google-YouTubeSample/1.0");
//		headers.gdataVersion = "2";
//		// set up the HTTP transport
//		HttpTransport transport = new NetHttpTransport();
//		transport.defaultHeaders = headers;
//		transport.addParser(parser);
//		// build the YouTube URL
//		YouTubeUrl url = new YouTubeUrl(
//				"https://gdata.youtube.com/feeds/api/videos");
//		url.author = "searchstories";
//		url.maxResults = 2;
//		// build the HTTP GET request
//		HttpRequest request = transport.buildGetRequest();
//		request.url = url;
		// execute the request and the parse video feed
//		try {
//			VideoFeed feed = request.execute().parseAs(VideoFeed.class);
//		} catch (IOException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		for (Video video : feed.items) {
//			System.out.println();
//			System.out.println("Video title: " + video.title);
//			System.out.println("Description: " + video.description);
//			System.out.println("Play URL: " + video.player.defaultUrl);
//		}
	}

	private void startVideo(String videoID) {
		// default youtube app 
    	Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:" + videoID)); 
    	List<ResolveInfo> list = getPackageManager().queryIntentActivities(i, PackageManager.MATCH_DEFAULT_ONLY); 
    	if (list.size() == 0) { 
    		// default youtube app not present or doesn't conform to the standard we know 
    		// use our own activity 
    		
    		Log.d("BrowseVideos", "No YouTube player");
//    		i = new Intent(getApplicationContext(), YouTube.class); 
//    		i.putExtra("VIDEO_ID", videoID); 
    	}
    	startActivity(i); 
    	}
}